package wb.is.besti.edu.cd.javalibgame;

import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * Created by asus on 2017/12/11.
 */

public class HardGameActivity extends AppCompatActivity {

    private int score = 0;
    private TextView HardScore, HardBestScore;
    private LinearLayout root = null;
    private HardGameView HardView;
    private AnimaLayer animLayer = null;
    public static final String SP_KEY_BEST_SCORE = "hardbestScore";
    private static HardGameActivity hardGameActivity = null;
    public HardGameActivity(){
        hardGameActivity = this;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hard_game);
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
        root = (LinearLayout) findViewById(R.id.hardcontainer);
        /*
        root.setBackgroundResource(R.drawable.bg);
        UnfoldButton unfoldButton = (UnfoldButton)findViewById(R.id.hardunfoldButton);
        unfoldButton.addElement(R.drawable.regame, R.color.colorPrimary, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HardView.startGame();

            }
        });
        unfoldButton.addElement(R.drawable.ic_action_sun,R.color.darkcyan,null);
        unfoldButton.addElement(R.drawable.ic_action_twitter,R.color.lightblue,null);
        unfoldButton.setmRotatable(true);
        unfoldButton.setmScale(1);
        unfoldButton.setLength(250);
        unfoldButton.setAngle(90);
        */
        HardScore = (TextView)findViewById(R.id.hardScore);
        HardScore.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/type.tff"));
        HardScore.setTextColor(0xffF08080);
        HardBestScore = (TextView)findViewById(R.id.hardBestScore);
        HardBestScore.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/type.tff"));
        HardBestScore.setTextColor(0xff800000);
        HardView = (HardGameView)findViewById(R.id.hardgameview);
        animLayer = (AnimaLayer) findViewById(R.id.animLayer);

    }
    public static HardGameActivity getHardGameActivity(){
        return hardGameActivity;
    }
    public AnimaLayer getAnimLayer() {
        return animLayer;
    }
    public void saveBestScore(int s) {   //保存数据，将最大的值存到sd卡中
        SharedPreferences.Editor e = getPreferences(MODE_PRIVATE).edit();
        e.putInt(SP_KEY_BEST_SCORE, s);
        e.commit();
    }
    public void clearScore() {
        score = 0;
        showScore();
    }
    public void showScore() {
        HardScore.setText(score + "");
    }
    public void addScore(int s) {
        score += s;
        showScore();

        int maxScore = Math.max(score, getBestScore());
        saveBestScore(maxScore);
        showBestScore(maxScore);
    }public int getBestScore() {
        return getPreferences(MODE_PRIVATE).getInt(SP_KEY_BEST_SCORE, 0);
    }
    public void showBestScore(int s) {   //最高纪录的那个地方会显示出保存的最好的成绩
        HardBestScore.setText(s + "");
    }
}
